<template>
    <view class="activities">
        <view class="activities-item" v-for="(item, index) in activityList" :key="index">
            <image @click="activity(item)" :src="item.image" mode="widthFix" />
        </view>
        <!-- 加载更多 -->
        <uni-load-more :status="status" :content-text="contentText" />
    </view>
</template>
<script>
export default {
    name: "activities",
    props: {},
    data() {
        return {
            activityList: [], //热门数据列表
            current_page: 1, //当前页
            last_page: 1, //最后一页
            total: 0, //总条数
            reload: false, //判断是否上拉
            status: "loading",
            contentText: {
                contentdown: "",
                contentrefresh: "疯狂加载中...",
                contentnomore: "",
            },
        };
    },
    computed: {},
    watch: {},
    mounted() { },
    onLoad(options) {
        this.getHotList();
    },
    // 监听上拉
    onPullDownRefresh() {
        this.reload = true;
        this.current_page = 1;
        this.activityList = [];
        this.getHotList();
    },
    onReachBottom() {
        //判断是否最后一页
        if (this.activityList.length >= this.total) {
            this.status = "noMore";
            return;
        } else {
            this.reload = false;
            this.status = "loading";
            this.current_page = this.current_page + 1; //页码+1
            this.loadData();
        }
    },
    methods: {
        //获取热门活动列表
        async getHotList() {
            await uni.request({
                url: "/increased.index/GetActivityList",
                data: {},
                method: "POST",
                success: (res) => {
                    console.log(res, "热门");
                    uni.stopPullDownRefresh(); //暂停下
                    this.activityList = this.reload ? res.data.data : this.activityList.concat(res.data.data); //数据 追加
                    this.current_page = res.data.current_page; //当前页码
                    this.last_page = res.data.last_page; //总页码
                    this.total = res.data.total;
                    this.status = res.data.total == 0 ? "noMore" : "more";
                },
                fail: (error) => { },
            });
        },
        // 热门推荐
        activity(item) {
            console.log(item, "热门推荐");
            if (item.jump_type == "shop") {
                console.log("进入商家店铺");
                uni.navigateTo({
                    url: `/pages/shop/index?id=${item.jump_id}`,
                });
            } else if (item.jump_type == "goods") {
                console.log("进入正常商品详情");
                uni.navigateTo({ url: "/pages/product/goods?id=" + item.jump_id });
            } else if (item.jump_type == "score") {
                console.log("进入积分详情");
                uni.navigateTo({ url: "/pages/user/member/details?id=" + item.jump_id });
            } else if (item.jump_type == "groups") {
                console.log("进入拼团详情");
                uni.navigateTo({ url: "/pages/apps/groups/goods?id=" + item.jump_id });
            }
        },
    },
};
</script>
<style lang="scss" scoped>
.activities {
    width: 100%;

    .activities-item {
        width: 100%;
        text-align: center;
        margin: 20rpx 0;

        image {
            text-align: center;
            display: inline-block;
        }
    }
}
</style>
